"""
@File    ：ui_test_h5.py
@Author  ：ixiaodu
@Date    ：2024/5/16
@Desc    ：
"""
# 导包
import requests
from time import sleep
from selenium import webdriver
from selenium.webdriver import Keys, ActionChains
from selenium.webdriver.common.by import By

from selenium.webdriver.chrome.service import Service
from utils.get_browser_driver import determine_google_drive

# 实例化浏览器
driver = webdriver.Chrome(service=Service(determine_google_drive()))

# 打开网址
driver.get('http://192.168.1.47/mobile')
# 最大化浏览器
driver.maximize_window()


# 进行登录操作
url = 'http://192.168.1.47/api/authq/sms/sendLoginValidCode'
json = {"phone": '15509870005'}
driver.find_element(By.XPATH, "//input[@type='number']").send_keys(json["phone"])
sleep(1)
res = requests.post(url=url, json=json)
sleep(3)
driver.find_element(By.XPATH, "(//input[@type='number'])[2]").send_keys(res.json()['msg'])
sleep(1)
driver.find_element(By.CSS_SELECTOR, ".loginBtn:nth-child(5)").click()
sleep(1)
driver.find_element(By.CSS_SELECTOR, ".ensure-button").click()
sleep(3)

driver.find_element(By.CSS_SELECTOR, ".top-right-image").click()
sleep(2)
driver.find_element(By.CSS_SELECTOR, "uni-view:nth-of-type(7) > .menu-text").click()
sleep(3)
driver.find_element(By.CSS_SELECTOR, ".u-scroll-box > uni-view:nth-of-type(3)").click()
sleep(2)
driver.find_element(By.CSS_SELECTOR, ".uni-scroll-view-content > uni-view:nth-of-type(5)").click()
sleep(1)
driver.find_element(By.CSS_SELECTOR, ".skin-btn-bgColor-transition").click()
sleep(1)
driver.find_element(By.CSS_SELECTOR, "uni-view:nth-of-type(1) > .cell-row-right > uni-view:nth-of-type(5)").click()
sleep(1)
driver.find_element(By.CSS_SELECTOR, "uni-view:nth-of-type(3) > .cell-row-right > uni-view:nth-of-type(1)").click()
sleep(1)
driver.find_element(By.CSS_SELECTOR, "uni-view:nth-of-type(4) > .cell-row-right > uni-view:nth-of-type(2)").click()
sleep(1)
driver.find_element(By.CSS_SELECTOR, ".uni-textarea-textarea").send_keys("测试")
sleep(1)
# driver.find_element(By.CSS_SELECTOR, ".u-list-item").click()
driver.find_element(By.CSS_SELECTOR, "uni-page-body .bottom-container .button-container:nth-of-type(1)").click()
sleep(1)
driver.find_element(By.CSS_SELECTOR, ".submit-button").click()
sleep(1)

text = driver.find_element(By.CSS_SELECTOR, ".page-title")
print(text.text)

# 时间轴看效果
sleep(3)

driver.quit()
